import {
    MAJOR_TALENT_PLAN_FILE,
    TEACHER_ARRANGEMENT,
    TEACHER_ASSESSMENT_METHOD,
    TEACHER_ATTENDANCE,
    TEACHER_CLASSROOM_APPLICATION,
    TEACHER_CLASSROOM_APPLICATION_MANAGEMENT,
    TEACHER_CLASSROOM_MY_APPLICATION,
    TEACHER_COURSE_CHANGE_APPLICATION,
    TEACHER_COURSE_CHANGE_APPLICATION_MANAGEMENT,
    TEACHER_COURSE_INFO,
    TEACHER_COURSE_SCHEDULING,
    TEACHER_COURSE_STANDARD,
    TEACHER_COURSEWARE_MANAGEMENT,
    TEACHER_DATA_STATISTICS,
    TEACHER_DISTRIBUTION,
    TEACHER_GRADUATE_INFO_MANAGEMENT,
    TEACHER_LOG,
    TEACHER_MAKEUP_ARRANGEMENT,
    TEACHER_MATERIAL_DATA_STATISTICS,
    TEACHER_NEW_INVENTORY,
    TEACHER_RETAKE_ARRANGEMENT,
    TEACHER_SCHEDULE_INFO,
    TEACHER_SELECTION_EXCHANGE,
    TEACHER_SUBSCRIPTION_PLAN,
    TEACHER_TALENT_PLAN,
    TEACHER_TEACHER_INFO,
    TEACHER_TEACHING_AIDS,
    TEACHER_TEACHING_PLAN
} from "../../api/api";
import {getLocalStorage} from "@/util/storage.util";
import {getDataByGet, getDataByPost} from "@/util/getdata.util";
import {ElMessage} from "element-plus";

//获取教师人才培养方案
export function getTeacherTalentPlan(department: any, majorName: any, callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`${TEACHER_TALENT_PLAN}?department=${department}&majorName=${majorName}`, null)
        .then((res: any) => {
            callback(res.datas)
        })
        .catch((err: any) => {
            ElMessage({
                message: "获取人才培养方案失败",
                type: "error",
                duration: 2000
            });
        })
}

export function searchTeacherTalentPlan(majorCode: any) {
    return `http://localhost:8080${MAJOR_TALENT_PLAN_FILE}?majorId=${majorCode}`
}

//获取授课课程信息
export function getTeacherCourseInfo(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_COURSE_INFO}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "获取授课课程信息失败",
                type: "error",
                duration: 2000
            });
        })

}

//获取教师教学资料——课程标准
export function getTeacherCourseStandard(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`${TEACHER_COURSE_STANDARD}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            callback(res.datas)
        })
        .catch((err: any) => {
            ElMessage({
                message: "获取课程标准失败",
                type: "error",
                duration: 2000
            });
        })
}

//获取教师教学资料——教学计划
export function getTeacherTeachingPlan(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    return `http://localhost:8080${TEACHER_TEACHING_PLAN}?teacher-number=${teacherNumber}`
}

//获取教师教学资料——课件管理
export function getTeacherCoursewareManagement(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_COURSEWARE_MANAGEMENT}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            console.log(err)
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

// 获取学生教学资料课件
export function getTeacherCourseWare(url: any) {
    return `http://localhost:8080${TEACHER_COURSEWARE_MANAGEMENT}?code=${url}`
}

//获取教师信息查询
export function getTeacherTeacherInfo(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_TEACHER_INFO}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

//获取教师课表查询
export function getTeacherScheduleInfo(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_SCHEDULE_INFO}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "获取课表失败",
                type: "error",
                duration: 2000
            });
        })
}

//获取考务管理——考试信息——考试安排
export function getTeacherArrangement(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_ARRANGEMENT}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

//获取考务管理——考试信息——补考安排
export function getTeacherMakeupArrangement(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_MAKEUP_ARRANGEMENT}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

//获取考务管理——考试信息——重修考试安排
export function getTeacherRetakeArrangement(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_RETAKE_ARRANGEMENT}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

//获取考务管理——考试信息——考试数据统计
export function getTeacherDataStatistics(courseId: any, callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    getDataByGet(`http://localhost:8080${TEACHER_DATA_STATISTICS}?course-id=${courseId}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "获取考试数据失败",
                type: "error",
                duration: 2000
            });
        })
}

//获取考务管理——考核方式申报
export function getTeacherAssessmentMethod(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_ASSESSMENT_METHOD}?`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

//获取考务管理——排课
export function getTeacherCourseScheduling(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_COURSE_SCHEDULING}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

//获取教材管理——教材征订计划
export function getTeacherSubscriptionPlan(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_SUBSCRIPTION_PLAN}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

//获取教材管理——教材选取、调换及审核
export function getTeacherSelectionExchange(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_SELECTION_EXCHANGE}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

//获取教材管理——教学辅助教材
export function getTeacherTeachingAids(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_TEACHING_AIDS}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

//获取教材管理——新书入库
export function getTeacherNewInventory(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_NEW_INVENTORY}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

export function postTeacherNewInventory(form: any, callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let studentNumber: string = UserInfo.userInfo.referenceId
    getDataByPost(`http://localhost:8080${TEACHER_NEW_INVENTORY}?student-number=${studentNumber}`, form, null)
        .then((res: any) => {
            if (res.code === 200) {
                ElMessage({
                    message: "提交成功",
                    type: "success",
                    duration: 2000
                });
                callback()
            }
        })
        .catch(err => {
            ElMessage({
                message: "提交失败",
                type: "error",
                duration: 2000
            });
        })
}

//获取教材管理——发放管理
export function getTeacherDistribution(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_DISTRIBUTION}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            // ElMessage({
            //     message: "服务器出错了*-*",
            //     type: "error",
            //     duration: 2000
            // });
        })
}

//获取教材管理——数据统计
export function getTeacherMaterialDataStatistics(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_MATERIAL_DATA_STATISTICS}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "获取教材数据失败",
                type: "error",
                duration: 2000
            });
        })
}

//获取教师申请管理——教室申请
export function getTeacherClassroomApplication(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_CLASSROOM_APPLICATION}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

//获取教师申请管理——我的申请
export function getTeacherClassroomMyApplication(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_CLASSROOM_MY_APPLICATION}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

//获取教师申请管理——申请管理
export function getTeacherClassroomApplicationManagement(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_CLASSROOM_APPLICATION_MANAGEMENT}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

//获取调课管理——调课申请
export function getTeacherCourseChangeApplication(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_COURSE_CHANGE_APPLICATION}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

//获取调课管理——调课申请管理
export function getTeacherCourseChangeApplicationManagement(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_COURSE_CHANGE_APPLICATION_MANAGEMENT}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

//获取毕业生信息管理
export function getTeacherGraduateInfoManagement(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_GRADUATE_INFO_MANAGEMENT}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "获取毕业生信息失败",
                type: "error",
                duration: 2000
            });
        })
}

//获取教师考核——教师考勤
export function getTeacherAttendance(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_ATTENDANCE}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

//获取教师考核——教学日志
export function getTeacherLog(callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080${TEACHER_LOG}?teacher-number=${teacherNumber}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch(err => {
            ElMessage({
                message: "服务器出错了*-*",
                type: "error",
                duration: 2000
            });
        })
}

/**
 * 新建文件夹
 * @param courseId
 * @param dir 父目录路径
 * @param dirName 文件夹名称
 * @param callback 回调函数
 */
export function createNewDir(courseId: any, dir: any, dirName: any, callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080/teacher/teaching-data/materials/courseware-management/create/directory?teacher-number=${teacherNumber}&dir=${dir}&dirName=${dirName}&courseId=${courseId}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback()
            }
        })
        .catch((err: any) => {
            ElMessage({
                message: "创建失败",
                type: "error",
                duration: 2000
            });
        })
}

/**
 * 删除文件/文件夹
 * @param courseId
 * @param dir
 * @param fileName
 * @param callback
 */
export function deleteDir(courseId: any, dir: any, fileName: any, callback: Function) {
    let UserInfo = JSON.parse(<string>getLocalStorage("UserInfo"))
    let teacherNumber: string = UserInfo.userInfo.referenceId
    getDataByGet(`http://localhost:8080/teacher/teaching-data/materials/courseware-management/delete/directory?teacher-number=${teacherNumber}&dir=${dir}&fileName=${fileName}&courseId=${courseId}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback()
            }
        })
        .catch((err: any) => {
            ElMessage({
                message: "操作失败",
                type: "error",
                duration: 2000
            });
        })
}

/**
 * 上传文件
 * @param form
 * @param callback
 */
export function uploadFile(form: any, callback: Function) {
    getDataByPost('http://localhost:8080/teacher/teaching-data/materials/courseware-management/upload', form, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback()
            }
        })
        .catch((err: any) => {
            ElMessage({
                message: "上传失败",
                type: "error",
                duration: 2000
            });
        })
}

/**
 * 获取数据库表
 */
export function getTables(callback: Function) {
    getDataByGet('http://localhost:8080/table', null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch((err: any) => {
            console.log(err)
            ElMessage({
                message: "获取数据失败",
                type: "error",
                duration: 2000
            });
        })
}

/**
 * 获取表格详细信息
 * @param tableName
 * @param entityClass
 * @param callback
 */
export function getTableData(tableName: any, entityClass: any, callback: Function) {
    getDataByGet(`http://localhost:8080/table/select?tableName=${tableName}&entityClass=${entityClass}`, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch((err: any) => {
            console.log(err)
            ElMessage({
                message: "获取数据失败",
                type: "error",
                duration: 2000
            });
        })
}

export function updateTableData(tableName: any, entityClass: any, form: any, callback: Function) {
    getDataByPost(`http://localhost:8080/table/update?tableName=${tableName}&entityClass=${entityClass}`, form, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch((err: any) => {
            console.log(err)
            ElMessage({
                message: "更新失败",
                type: "error",
                duration: 2000
            });
        })
}

export function deleteTableData(tableName: any, entityClass: any, form: any, callback: Function) {
    getDataByPost(`http://localhost:8080/table/delete?tableName=${tableName}&entityClass=${entityClass}`, form, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch((err: any) => {
            console.log(err)
            ElMessage({
                message: "操作失败",
                type: "error",
                duration: 2000
            });
        })
}

export function createTableData(tableName: any, entityClass: any, form: any, callback: Function) {
    getDataByPost(`http://localhost:8080/table/create?tableName=${tableName}&entityClass=${entityClass}`, form, null)
        .then((res: any) => {
            if (res.code === 200) {
                callback(res.datas)
            }
        })
        .catch((err: any) => {
            console.log(err)
            ElMessage({
                message: "操作失败",
                type: "error",
                duration: 2000
            });
        })
}